<template>
  <view>
    <!-- 地址信息区域 -->
    <view class="address_box" v-if="JSON.stringify(address) !== '{}'" @click="navAddress">
      <view class="me_data_top">
        <view class="addres_name">
          <view class="name">收货人: {{address.userName}}</view>
        </view>
        <view class="addres_phone">
          <view class="phone">电话: {{address.telNumber}}</view>
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view>
      </view>
      <view class="address_data_bottom" >
        <view class="address_title">地址: {{addstr}}</view>
      </view>
    </view>
    <!-- 选择地址按钮 -->
    <view class="address_button" v-else >
      <button 
        type="primary" 
        size="mini" 
        class="btnChooseAddress"
        @click="navAddress">请选择收货地址+</button>
    </view>
    <!-- 底部边框图 -->
    <image class="address_img" src="../../static/img_address.jpg" ></image>
  </view>
</template>

<script>
  import { mapState,mapMutations,mapGetters  } from 'vuex'
  export default {
    name:"my_address",
    data() {
      return {
      };
    },
    computed: {
      ...mapState('user',['address']),
      ...mapGetters('user',['addstr'])
    },
    methods: {
      ...mapMutations('user',['addAddress']),
      async navAddress() {
        // 1. 调用小程序提供的 chooseAddress() 方法，即可使用选择收货地址的功能
        //    返回值是一个数组：第 1 项为错误对象；第 2 项为成功之后的收货地址对象
        const [err,suess] = await uni.chooseAddress().catch(err => err)
        if(err === null && suess.errMsg === 'chooseAddress:ok') { 
          this.addAddress(suess)
        }
      }
    }
  }
</script>

<style lang="scss">
.address_img {
  width: 100%;
  height: 5px;
  display: block;
}
.address_button {
  height: 90px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.address_box {
  height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 5px;
  font-size: 12px;
  .me_data_top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    .addres_name {}
    .addres_phone {
      display: flex;
      .phone {
        margin-right: 3px;
      }
    }
  }
}
</style>